package server.modules.generator.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import server.common.utils.PageUtils;
import server.common.utils.Query;

import server.modules.generator.dao.ProjectDao;
import server.modules.generator.entity.ProjectEntity;
import server.modules.generator.entity.WorkGroupEntity;
import server.modules.generator.service.ProjectService;
import server.modules.generator.service.WorkGroupService;
import server.modules.sys.service.SysUserService;


@Service("projectService")
public class ProjectServiceImpl extends ServiceImpl<ProjectDao, ProjectEntity> implements ProjectService {

    @Autowired
    SysUserService sysUserService;
    @Autowired
    WorkGroupService workGroupService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProjectEntity> page = this.page(
                new Query<ProjectEntity>().getPage(params),
                new QueryWrapper<ProjectEntity>()
        );

        for (ProjectEntity sing : page.getRecords()) {
            sing.setCreateUserName(sysUserService.getById(sing.getCreateUser()).getShowname());
            sing.setOwnerName(sysUserService.getById(sing.getOwnerId()).getShowname());

            WorkGroupEntity workGroupEntity = workGroupService.getById(sing.getWorkId());
            if (null != workGroupEntity)
                sing.setWorkName(workGroupEntity.getName());
        }

        return new PageUtils(page);
    }

}